package com.majsubtense.core.events;

public class EventDispatcher {
    private final Event event;

    public EventDispatcher(Event event) {
        this.event = event;
    }

    public <T extends Event> void dispatch(EventHandler<T> handler) {
        EventType<? extends Event> eventType = event.getEventType();
        while (eventType != null) {
            if (handler.getEventType().equals(eventType)) {
                // noinspection unchecked
                handler.handle((T) event);
                break;
            }
            eventType = eventType.getSuperType();
        }
    }
}
